package com.skyline.common.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ShareTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3333841102260669234L;
	private static final Log LOGGER = LogFactory.getLog(ShareTag.class);
	private String type;
	private Long resourceId;
	private String value;
	private String curClass;
	private String imgSrc;

	public void setType(String type) {
		this.type = type;
	}

	public void setResourceId(Long resourceId) {
		this.resourceId = resourceId;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public void setCurClass(String curClass) {
		this.curClass = curClass;
	}

	public void setImgSrc(String imgSrc) {
		this.imgSrc = imgSrc;
	}

	@Override
	public int doEndTag() throws JspException {
		try {
			pageContext.getOut().println(getShareTag());
		} catch (IOException e) {
			LOGGER.warn("调用share出错", e);
		}
		return EVAL_BODY_INCLUDE;
	}
	
	public String getShareTag(){
		String tagContent="";
		tagContent+="<a href='javascript:Share.add(\""+type+"\",\""+resourceId+"\")' ";
		tagContent+="class='"+curClass+"' title='"+value+"'>";
		if(imgSrc==null){
			tagContent+=value;
		}
		else{
			tagContent+="<img src='"+imgSrc+"'/>";
		}
		tagContent+="</a>";
		return tagContent;
	}

}
